﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Reflection.Emit;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using static System.Windows.Forms.VisualStyles.VisualStyleElement;

namespace Bank_database_system
{
    public partial class 查询员工a : UserControl
    {

        private int pagesize = 11;

        public 查询员工a()
        {
            InitializeComponent();
            int staffCount = HR.GetHRNum(textBox5.Text, textBox2.Text, textBox1.Text, comboBox1.Text);
            if (staffCount < 0)
            {
                label1.Text = "0";
                label3.Text = "0";
                return;
            }
            label1.Text = Convert.ToString((staffCount - 1) / pagesize + 1);
            show();
        }


        private void show()
        {
            dataGridView1.DataSource = HR.HRtable(textBox5.Text, textBox2.Text, textBox1.Text, comboBox1.Text,Convert.ToInt32(label3.Text), pagesize);
            dataGridView1.RowHeadersVisible = false;
            dataGridView1.AllowUserToAddRows = false;
            dataGridView1.AllowUserToResizeColumns = false;
            dataGridView1.AllowUserToResizeRows = false;
            dataGridView1.ReadOnly = true;
            dataGridView1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
            dataGridView1.DoubleBuffered(true);
            foreach (DataGridViewColumn column in dataGridView1.Columns)
            {
                column.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
                column.HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter;
            }
        }

        private void 修改员工a_Load(object sender, EventArgs e)
        {

        }

        private void button2_Click(object sender, EventArgs e)
        {
            textBox1.Clear();
            textBox2.Clear();
            textBox5.Clear();
            comboBox1.ResetText();
            label3.Text = "1";
            int staffCount = HR.GetHRNum(textBox5.Text, textBox2.Text, textBox1.Text, comboBox1.Text);
            if (staffCount < 0)
            {
                label1.Text = "0";
                label3.Text = "0";
                return;
            }
            label1.Text = Convert.ToString((staffCount - 1) / pagesize + 1);
            show();
        }

        private void textBox5_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (!char.IsControl(e.KeyChar) && !char.IsDigit(e.KeyChar))
            {
                e.Handled = true;
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            label3.Text = "1";
            int staffCount = HR.GetHRNum(textBox5.Text, textBox2.Text, textBox1.Text, comboBox1.Text);
            if (staffCount < 0)
            {
                label1.Text = "0";
                label3.Text = "0";
                return;
            }
            label1.Text = Convert.ToString((staffCount - 1) / pagesize + 1);
            show();
        }

        private void button12_Click(object sender, EventArgs e)
        {
            string LastPageCount = label1.Text;
            int staffCount = HR.GetHRNum(textBox5.Text, textBox2.Text, textBox1.Text, comboBox1.Text);
            if (staffCount < 0)
            {
                label1.Text = "0";
                label3.Text = "0";
                return;
            }
            label1.Text = Convert.ToString((staffCount - 1) / pagesize + 1);
            if (LastPageCount == label1.Text)
            {
                int page = Convert.ToInt32(label3.Text);
                if (page > 1)
                {
                    page--;
                    label3.Text = Convert.ToString(page);
                }
            }
            else
            {
                label3.Text = "1";
            }
            show();
        }

        private void button13_Click(object sender, EventArgs e)
        {
            string LastPageCount = label1.Text;
            int staffCount = HR.GetHRNum(textBox5.Text, textBox2.Text, textBox1.Text, comboBox1.Text);
            if (staffCount < 0)
            {
                label1.Text = "0";
                label3.Text = "0";
                return;
            }
            label1.Text = Convert.ToString((staffCount - 1) / pagesize + 1);
            if (LastPageCount == label1.Text)
            {
                int page = Convert.ToInt32(label3.Text);
                if (page < Convert.ToInt32(LastPageCount))
                {
                    page++;
                    label3.Text = Convert.ToString(page);
                }
            }
            else
            {
                label3.Text = "1";
            }
            show();
        }

    }
}
